from collections import deque
class myque:
    def __init__(self):
        self.que=deque()

    def pop(self,val):
        if len(self.que)>0 and self.que[0]==val:
            self.que.popleft()

    def push(self,val):
        while len(self.que)>0 and self.que[-1]<val:
            self.que.pop()
        self.que.append(val)

    def get_max(self):
        return self.que[0]
    
def solve(lst,k):
    ans=[]
    que=myque()
    for i in range(k): que.push(lst[i])
    for i in range(len(lst)-k+1):
        ans.append(que.get_max())
        if i+k<len(lst):
            que.pop(lst[i])
            que.push(lst[i+k])
    return ans 

print(solve([1,3,-1,-3,5,3,6,7],3))

